//
//  ProfileManager.swift
//  CatPomodoroTimer
//
//  Created by Xuri Li on 2024/8/15.
//

import Foundation

class ProfileManager {
    private let profileKey = "userProfile"
    
    func saveProfile(_ profile: Profile) {
        if let encoded = try? JSONEncoder().encode(profile) {
            UserDefaults.standard.set(encoded, forKey: profileKey)
        }
    }
    
    func loadProfile() -> Profile {
        if let data = UserDefaults.standard.data(forKey: profileKey),
           let profile = try? JSONDecoder().decode(Profile.self, from: data) {
            return profile
        }
        return Profile.default
    }
}
